package com.example.chapter05;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class DrawableShapeActivity extends AppCompatActivity implements View.OnClickListener {

    private View view_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawable_shape);
        view_content = findViewById(R.id.v_content);
        findViewById(R.id.btn_rect).setOnClickListener(this);
        findViewById(R.id.btn_oval).setOnClickListener(this);
        // 设置默认显示矩形背景：金色
        view_content.setBackgroundResource(R.drawable.shape_rect_gold);
    }

    @Override
    public void onClick(View v) {
        // 点击按钮时，根据按钮的ID设置不同的背景形状
        if (v.getId() == R.id.btn_rect) {
            view_content.setBackgroundResource(R.drawable.shape_rect_gold);
        } else {
            view_content.setBackgroundResource(R.drawable.shape_oval_rose);
        }
    }
}